// 下划线转换驼峰
const lodash=require('lodash')

function toHump(name) {
    return name.replace(/\_(\w)/g, function (all, letter) {
        return letter.toUpperCase();
    });
}

// 驼峰转换下划线
function toLine(name) {
    return name.replace(/([A-Z])/g, "_$1").toLowerCase();
}


function firstworldupp(s) {
    return s[0].toUpperCase() + s.slice(1);
}

function firstworlddown(s) {
    return s[0].toLowerCase() + s.slice(1);
}

/*
* @desc 把object转化成 key=value&key2=value2
* */
function createUrlParams(params){
    var strParams=""
    lodash.map(params,(value,key)=>{
        strParams+=`${toHump(key)}=${encodeURIComponent(value)}&`
    })
    strParams=strParams.substring(0,strParams.length-1)
    return strParams
}

 function getUrlParamNative(str,n) {
    var e, r;
    return r = new RegExp("(^|&)" + n + "=([^&]*)(&|$)"), e = str.match(r), null !== e ? decodeURI(e[2]) : null
};

module.exports = {
    getUrlParamNative,
    createUrlParams,
    firstworldupp,
    toHump,
    firstworlddown,
    toLine
}
